#include <cstdio>
#include <algorithm>

using namespace std;

int max( int a, int b ) { return ( a > b ) ?a :b; }
int min( int a, int b ) { return ( a < b ) ?a :b; }

struct Edge
{
    int u, v, w;
};

struct Node
{
    int id, a;
};

bool operator < ( const Node &a, const Node &b )
{
    return a.a < b.a;
}

Edge edge[ 10000 ];
int n, m, d[ 1010 ], l, r, D;
Node a[ 1010 ];

void init( )
{
    int i, minn = 1000000000, maxn = 0, t;
    scanf("%d%d", &n, &D);
    for ( i = 0; i < n; i++ )
    {
        a[ i ].id = i;
        scanf("%d", &a[ i ].a);
        if ( minn > a[ i ].a )
        {
            minn = a[ i ].a;
            l = i;
        }
        if ( maxn < a[ i ].a )
        {
            maxn = a[ i ].a;
            r = i;
        }
    }
    if ( l > r ) { t = l; l = r; r = t; }
    sort( a, a + n );
    m = 0;
    for ( i = 1; i < n; i++ )
    {
        edge[ m ].u = i; edge[ m ].v = i - 1; edge[ m ].w = -1;
        m++;
        edge[ m ].u = min( a[ i - 1 ].id, a[ i ].id ); edge[ m ].v = max( a[ i - 1 ].id, a[ i ].id ); edge[ m ].w = D;
        m++;
    }
//    for ( i = 0; i < m; i++ ) printf("%d %d %d\n", edge[ i ].u, edge[ i ].v, edge[ i ].w);
//    printf("%d %d\n", l, r);
}

bool work( )
{
    int i, j;
    for ( i = 0; i < n; i++ )
        d[ i ] = 1000000000;
    d[ l ] = 0;
    for ( i = 0; i < n; i++ )
        for ( j = 0; j < m; j++ )
            if ( d[ edge[ j ].v ] > d[ edge[ j ].u ] + edge[ j ].w )
                d[ edge[ j ].v ] = d[ edge[ j ].u ] + edge[ j ].w;
    for ( i = 0; i < m; i++ )
        if ( d[ edge[ i ].v ] > d[ edge[ i ].u ] + edge[ i ].w )
            return false;
    return true;
}

int main( )
{
    int t, cas = 1;
    scanf("%d", &t);
    while ( t-- )
    {
        init( );
        printf("Case %d: ", cas++);
        if ( work( ) )
            printf("%d\n", d[ r ]);
        else
            printf("-1\n");
    }
    return 0;
}
